package com.codemart.lanze.core.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class JsonUtils {

	/**
	 * 将对象转换为Json数据
	 *
	 * @param object
	 * @return
	 */
	public static String toJson(Object object) {
		return JSON.toJSONString(object, SerializerFeature.BrowserCompatible);
	}

	/**
	 * 将对象转换为Json数据,如果对象中存在时间数据可以自定义时间显示格式
	 *
	 * @param object
	 * @param format
	 * @return
	 */
	public static String toJson(Object object, String format) {
		if (format == null) {
			return toJson(object);
		}
		return JSON.toJSONStringWithDateFormat(object, format, SerializerFeature.WriteDateUseDateFormat);
	}

}